/*
 * @Author: CB
 * @Date: 2023-07-27 14:48:03
 * @Description: 安卓系统管理
 */
import { JAVAFilePathEnum } from "../define/PluginDefine";
import { PluginSys } from "../PluginSys";



const trace = function (...args) {
    console.log("PluginSysAndroid", ...args);
}
const traceError = function (...args) {
    console.error("PluginSysAndroid", ...args);
}

export class PluginSysAndroid extends PluginSys {
    /** 保存不会变动的数据，减少通讯次数 */
    private tempData = {};

    getDeviceId(): string {
        trace('小黑屋获取设备id', 'PluginSysAndroid');
        const keyName = "_deviceId_";
        if (!this.tempData[keyName]) {
            this.tempData[keyName] = this.callStaticMethod(JAVAFilePathEnum.SysHelper, 'getDeviceId', '()Ljava/lang/String;');
            if (!this.tempData[keyName]) {
                trace('获取设备id失败');
                this.tempData[keyName] = super.getDeviceId();
            }
        }
        return this.tempData[keyName] || '';
    }


    /** 调用手机震动
     * @param milliseconds 震动时长 单位毫秒 [1000,2000,3000] 震动1秒，停2秒，再震动3秒
     * @param repeat 重复次数
     */
    vibrate(milliseconds: number[], repeat: number) {
        this.callStaticMethod(JAVAFilePathEnum.SysHelper, 'vibrate', '(Ljava/lang/String;I)V', this.formatArray(milliseconds), Math.round(repeat));
    }
}




// int	I
// float	F
// boolean	Z
// String	Ljava/lang/String;